﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using ExtAspNet;
using Ylh.BLL;

public partial class Module_StaffManger_StaffManger : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["DeID"] != null)
            {
                BindGvlist(Request.QueryString["DeID"].ToString());
            }
        }

    }

    private void BindGvlist(string DepartmentID)
    {
        StaffBLL sbll = new StaffBLL(DbConnectionStr);

        Grid1.DataSource = sbll.GetStaffData(DepartmentID);
        Grid1.DataBind();
    }


    protected void Grid1_RowCommand(object sender, ExtAspNet.GridCommandEventArgs e)
    {
        string str = Grid1.DataKeys[e.RowIndex][0].ToString();
        switch (e.CommandName)
        {
            case "UpdateInfo":
                PageContext.RegisterStartupScript(Window2.GetShowReference("AddStaff.aspx?StaffID=" + str, "修改员工"));
                break;
            case "UpdateRoleInfo":
                PageContext.RegisterStartupScript(Window3.GetShowReference("../RoleManger/RoleTree2.aspx?StaffID=" + str, "选择角色"));
                break;
            case "UpdatePwd":
                PageContext.RegisterStartupScript(Window4.GetShowReference("ResetPwd.aspx?StaffID=" + str, "修改密码"));
                 break;
            default:
                break;
        }
    }
    protected void BtnImport_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["DeID"] == null)
        {
            Alert.Show("请先选择左边的部门");
            return;
        }
        PageContext.RegisterStartupScript(Window1.GetShowReference("StaffImport.aspx?DeID=" + Request.QueryString["DeID"].ToString(), "导入员工信息"));
    }
    protected void BtnAdd_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["DeID"] == null)
        {
            Alert.Show("请先选择左边的部门");
        }

        PageContext.RegisterStartupScript(Window2.GetShowReference("AddStaff.aspx", "添加员工"));
    }
    protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
    {
        Grid1.PageIndex = e.NewPageIndex;
    }


    protected void BtnDel_Click(object sender, EventArgs e)
    {
        List<string> li = base.GetCheckID(Grid1);

        if (li.Count == 0)
        {
            Alert.Show("请先选择需要删除的员工");
        }

        try
        {
            StaffBLL blls = new StaffBLL(DbConnectionStr);
            blls.Delete(li);
            BindGvlist(Request.QueryString["DeID"].ToString());
            Alert.Show("员工删除成功,但是拥有客户的员工则不能删除");
        }
        catch
        {
            Alert.Show("删除失败,请与管理员联系");
            return;
        }
    }
    protected void Window1_Close(object sender, WindowCloseEventArgs e)
    {
        if (Request.QueryString["DeID"] != null)
        {
            BindGvlist(Request.QueryString["DeID"].ToString());
        }
    }





}